package cn.itsource.test2._05topics;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Customer1 {
    public static final String TESTCUSTOMER1 = "TESTCUSTOMER1";
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(TESTCUSTOMER1, true, false, false, null);
        channel.queueBind(TESTCUSTOMER1, Producer.TOPICSTEST, "error1.*");
        Consumer callback = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("接收到的参数："+ new String(body));
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        };
        // 监听队列
        channel.basicConsume(TESTCUSTOMER1, false, callback);

    }
}
